home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 7.5 KB | 265 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWArcShp.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWARCSHP_H
- #include "FWArcShp.h"
- #endif
-
- #ifndef FWOVLSHP_H
- #include "FWOvlShp.h"
- #endif
-
- #ifndef FWRASTER_H
- #include "FWRaster.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- C Includes -----
-
- #if defined(FW_BUILD_MAC) & !defined(__FP__)
- #include <FP.h>
- #endif
-
- #ifdef FW_BUILD_WIN
- #include <math.h>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgraphxshape
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CArcShape, FW_CBoundedShape)
-
- FW_REGISTER_ARCHIVABLE_CLASS(FW_LArcShape, FW_CArcShape, FW_CArcShape::Read, FW_CShape::Write)
-
- //========================================================================================
- // class FW_CArcShape
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::FW_CArcShape
- //----------------------------------------------------------------------------------------
-
- FW_CArcShape::FW_CArcShape(const FW_CArcShape& other) :
- FW_CBoundedShape(other),
- fStartAngle(other.fStartAngle),
- fArcAngle(other.fArcAngle)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::FW_CArcShape
- //----------------------------------------------------------------------------------------
-
- FW_CArcShape::FW_CArcShape(const FW_CRect& rect,
- short startAngle,
- short arcAngle,
- FW_ERenderVerbs renderVerb,
- const FW_PInk& ink,
- const FW_PStyle& style) :
- FW_CBoundedShape(rect, renderVerb, ink, style, FW_kNormalFont),
- fStartAngle(startAngle),
- fArcAngle(arcAngle)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::FW_CArcShape
- //----------------------------------------------------------------------------------------
-
- FW_CArcShape::FW_CArcShape(FW_CReadableStream& archive) :
- FW_CBoundedShape(archive)
- {
- archive >> fStartAngle;
- archive >> fArcAngle;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::~FW_CArcShape
- //----------------------------------------------------------------------------------------
-
- FW_CArcShape::~FW_CArcShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CArcShape& FW_CArcShape::operator=(const FW_CArcShape& other)
- {
- if (this != &other)
- {
- FW_CBoundedShape::operator=(other);
-
- fStartAngle = other.fStartAngle;
- fArcAngle = other.fArcAngle;
- }
-
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::Render
- //----------------------------------------------------------------------------------------
-
- void FW_CArcShape::Render(FW_CGraphicContext& gc) const
- {
- gc.GetRasterizer()->RenderArc(gc,
- fRect,
- fStartAngle, fArcAngle,
- GetRenderVerb(),
- fInk,
- fStyle);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::RenderArc
- //----------------------------------------------------------------------------------------
-
- void FW_CArcShape::RenderArc(FW_CGraphicContext& gc,
- const FW_CRect& rect,
- short startAngle, short arcAngle,
- FW_ERenderVerbs renderVerb,
- const FW_PInk& ink,
- const FW_PStyle& style)
- {
- gc.GetRasterizer()->RenderArc(gc,
- rect,
- startAngle, arcAngle,
- renderVerb,
- ink,
- style);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::CalcAngle
- //----------------------------------------------------------------------------------------
- // Need to be changed. Could do better than that.
-
- short FW_CArcShape::CalcAngle(const FW_CPoint& test) const
- {
- FW_Double width = (fRect.right - fRect.left).AsDouble();
- FW_Double height = (fRect.bottom - fRect.top).AsDouble();
-
- FW_CFixed fxZero = FW_IntToFixed(0);
-
- if (test.y == fxZero || height == 0)
- return test.x < fxZero ? 270 : 90;
-
- if (test.x == fxZero || width == 0)
- return test.y < fxZero ? 180 : 0;
-
- FW_Double arc = atan(test.y.AsDouble() * height / test.x.AsDouble() * width);
- // FW_Double arc = atan2((FW_Double)test.x * width, (FW_Double)test.y * height);
-
- arc = 90.0 - ((180.0 * arc) / 3.1415926536);
-
- return arc;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::HitTest
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CArcShape::HitTest(FW_CGraphicContext& gc,
- const FW_CPoint& test,
- FW_CFixed tolerance) const
- {
- if(fRenderVerb == FW_kNoRendering)
- return FALSE;
-
- if (FW_CBoundedShape::HitTest(gc, test, tolerance))
- {
- short arcAngle = CalcAngle(test) - fStartAngle;
- if (((arcAngle & 0x8000) == (fArcAngle & 0x8000)) && // same sign
- FW_Absolute((long)fArcAngle) >= FW_Absolute((long)arcAngle))
- {
- FW_COvalShape oval(fRect, fRenderVerb);
- return oval.HitTest(gc, test, tolerance);
- }
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CShape* FW_CArcShape::Copy() const
- {
- return FW_NEW(FW_CArcShape, (*this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::GetGeometry
- //----------------------------------------------------------------------------------------
-
- void FW_CArcShape::GetGeometry(FW_CRect& rect, short& startAngle, short& arcAngle) const
- {
- rect = fRect;
- startAngle = fStartAngle;
- arcAngle = fArcAngle;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::SetGeometry
- //----------------------------------------------------------------------------------------
-
- void FW_CArcShape::SetGeometry(const FW_CRect& rect, short startAngle, short arcAngle)
- {
- fRect = rect;
- fStartAngle = startAngle;
- fArcAngle = arcAngle;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CArcShape::Flatten(FW_CWritableStream& archive) const
- {
- FW_CBoundedShape::Flatten(archive);
- archive << fStartAngle;
- archive << fArcAngle;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CArcShape::Read
- //----------------------------------------------------------------------------------------
-
- void* FW_CArcShape::Read(FW_CReadableStream& archive)
- {
- return FW_NEW(FW_CArcShape, (archive));
- }
-
-
-
-